package nid.gallery 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	/**
	 * ...
	 * @author Nidin P Vinayakan
	 */
	public class MediaGallery extends Sprite
	{
		
		public var view:View;
		
		public function MediaGallery() 
		{
			trace("MediaGallery Inited");
			init();
		}
		
		private function init():void 
		{
			/**
			 * Load XML file
			 */
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onXMLComplete);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			loader.load(new URLRequest('data.xml'));
		}
		
		private function onXMLComplete(e:Event):void 
		{
			
			/**
			 * Create Gallery Objects 
			 * 
			 * Create media viewer class
			 */
			view = new View();
			addChild(view);
			
			view.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			
			view.build(new XML(e.target.data));
			
		}
		
		private function onIOError(e:IOErrorEvent):void 
		{
			trace('io error');
		}
		
	}

}